package com.zy.sso.server.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.zy.sso.client.dto.BaseUser;
import com.zy.sso.client.dto.change_user_status.ChangeUserStatusDTO;
import com.zy.sso.client.dto.find_pwd.FindPwdDTO;
import com.zy.sso.client.dto.login.ClientInfo;
import com.zy.sso.client.dto.login.LoginDTO;
import com.zy.sso.client.dto.login.inter.ILogin;
import com.zy.sso.client.dto.login.inter.IRegist;
import com.zy.sso.client.dto.logout.LogoutDTO;
import com.zy.sso.client.dto.reset_pwd.ResetPwdDTO;
import com.zy.sso.client.exception.SsoException;
import com.zy.sso.inter.IUserController;
import com.zy.sso.server.service.UserService;

@RestController
public class UserController implements IUserController{

	@Autowired
	private UserService userService;
	
	/**
	 * 说明:用户注冊
	 * @param LoginDTO
	 * @return JwtUser
	 * **/
	@Override
	public BaseUser regist(@RequestBody @Validated({IRegist.class}) LoginDTO loginDTO) throws SsoException,ClassNotFoundException{
		return userService.regist(loginDTO);
	}
	
	/**
	 * 说明:用户登陆
	 * @param LoginDTO
	 * @return JwtUser
	 * @throws ClassNotFoundException 
	 * **/
	@Override
	public BaseUser login(@RequestBody @Validated({ILogin.class}) LoginDTO loginDTO) throws SsoException, ClassNotFoundException{
		return userService.login(loginDTO);
	}
	
	/**
	 * 说明:退出登陆
	 * @param gid
	 * @return JwtUser
	 * **/
	@Override
	public void loginOut(@RequestBody @Validated LogoutDTO logoutDto,@PathVariable("gid") String gid) throws SsoException{
		userService.loginOut(logoutDto,gid);
	}
	
	
	/**
	 * 说明:找回密码
	 * @param FindPwdDTO
	 * @param account
	 * @return JwtUser
	 * **/
	@Override
	public BaseUser findPwd(@RequestBody @Validated FindPwdDTO findPwdDto,@PathVariable String account) throws SsoException{
		return userService.findPwd(findPwdDto, account);
	}
	
	/**
	 * 说明:忘记密码
	 * @param ResetPwdDTO
	 * @param gid
	 * @return JwtUser
	 * @throws ClassNotFoundException 
	 * **/
	@Override
	public BaseUser resetPwd(@RequestBody @Validated ResetPwdDTO resetPwdDto,@PathVariable String gid) throws SsoException, ClassNotFoundException{
		return userService.resetPwd(resetPwdDto, gid);
	}
	
	/**
	 * 说明:获取用户登陆信息
	 * @param gid
	 * @return JwtUser
	 * **/
	@Override
	public List<ClientInfo> getLoginInfoByGid(@PathVariable("gid") String gid) throws SsoException{
		return userService.getLoginInfoByGid(gid);
	}
	
	/**
	 * 说明:获取用户账户信息
	 * @param gid
	 * @return JwtUser
	 * **/
	@Override
	public BaseUser getAccountInfoByGid(@PathVariable("gid") String gid) throws SsoException{
		return userService.getAccountInfoByGid(gid);
	}
	
	/**
	 * 说明:获取用户账户信息
	 * @param account
	 * @return JwtUser
	 * **/
	@Override
	public BaseUser getAccountInfoByAccount(@PathVariable("account") String account) throws SsoException{
		return userService.getAccountInfoByAccount(account);
	}
	
	/**
	 * 说明:更改用户状态
	 * @param ResetPwdDTO
	 * @param gid
	 * @return JwtUser
	 * **/
	@Override
	public BaseUser changeUserStatus(@PathVariable("account") String account,@Validated @RequestBody ChangeUserStatusDTO changeUserStatusDto){
		return userService.changeUserStatus(account,changeUserStatusDto);
	}



}
